from django.shortcuts import render
from apps.adj_optimize.models import OptimizeDetailList, OptimizePlanRedList
from django.core.paginator import Paginator, PageNotAnInteger, EmptyPage
from django.http import Http404
from django.conf import settings

# Create your views here.


def home(request):  # 主页
    posts = OptimizeDetailList.objects.all()  # 获取全部邻区优化清单对象
    return render(request, 'home.html', {'post_list': posts})


def plan(request):  # 邻区自动优化方案
    posts = OptimizePlanRedList.objects.all()
    paginator = Paginator(posts, settings.PAGE_NUM)
    page = request.GET.get('get')
    try:
        post_list = paginator.page(page)
    except PageNotAnInteger:
        post_list = paginator.page(1)
    except EmptyPage:
        post_list = paginator.page(paginator.num_pages)
    return render(request, 'plan.html', {'post_list': post_list})

def Execution(request): #工单执行
    posts = OptimizePlanRedList.objects.all()
    paginator = Paginator(posts, settings.PAGE_NUM)
    page = request.GET.get('get')
    try:
        post_list = paginator.page(page)
    except PageNotAnInteger:
        post_list = paginator.page(1)
    except EmptyPage:
        post_list = paginator.page(paginator.num_pages)
    return render(request, 'Execution.html', {'post_list':post_list})

def monitor(request):
    return render(request, 'monitor.html')

def login(request):
    return render(request, 'login.html')


